<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class MemberResource extends JsonResource
{
    protected $showSensitiveFields = false;

    public function toArray($request)
    {
        $sex = ['未知', '男', '女'];
        $data = [
            'avatar' => boolval($this->publisher) ? $this->publisher->avatar : $this->avatar,
            'id' => $this->id,
            'nickname' => boolval($this->publisher) ? $this->publisher->name : $this->nickname,
            'sex' => $this->sex,
            'sex_text' => $sex[$this->sex],
            'sign' => $this->sign,
            'topic_count' => $this->topic_count,
            'favs_count' => $this->favs_count,
            'relay_count' => $this->relay_count,
            'is_publisher' => $this->publisher_count,
            'can_examine' => $this->publisher && $this->publisher->is_examine == 1,
            'message_count' => $this->messages_count,
            'integral' => $this->integral,
            'phone' => $this->phone ? substr_replace($this->phone, '****', 3, 4) : '',
            'is_vip' => $this->is_vip,
            'vip_show_adv' => $this->vip_show_adv,
            'vip_end_date' => $this->vip_end_time > 0 ? date('Y-m-d H:i:s', $this->vip_end_time) : '',
        ];

        return $data;
    }
}
